﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ylh.ElvModel;
using Ylh.Data;
public partial class 示例OR测试_QuerySelect : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TbEvlutionText text = new TbEvlutionText();
        QuerySelect Query = new QuerySelect();
        Response.Write("<p>" + Query.Select(text).SelectField(text.Code, text.CreateDate).SelectFields + "</p>");
        Response.Write("<p>" + Query.StrSelectQuery+ "</p>");
        QuerySelect Query2 = new QuerySelect();
        Response.Write("<p>" + Query2.Select(text).SelectFields + "</p>");
        //Response.Write("<p>" + Query.SelectFild(text.Code, text.CreateDate).SelectFiled + "</p>");
    }
}

public class QuerySelect
{

    private bool isDistinct = false;
    public bool IsDistinct
    {
        get { return isDistinct; }
        set { isDistinct = value; }
    }

    private String selectFields;
    public String SelectFields
    {
        get { return selectFields; }
        set { selectFields = value; }
    }

    private String strSelectQuery;
    public String StrSelectQuery
    {
        get { return strSelectQuery; }
        set { strSelectQuery = value; }
    }

    private EntityBase Entity { get; set; }


    public QuerySelect Select(EntityBase EntityBase)
    {
        EntityBase.PropertyNameGetting += new EventHandler<PropertyNameGettingEventArgs>(EntityBase_PropertyNameGetting);
        StrSelectQuery = @" Select ";


        StrSelectQuery += IsDistinct ? " Distinct " : String.Empty;

        StrSelectQuery += String.IsNullOrEmpty(SelectFields) ? " * " : StrSelectQuery.TrimEnd(',');

        StrSelectQuery += " From " + EntityBase.TableName;
        return this;
    }

    protected void EntityBase_PropertyNameGetting(object sender, PropertyNameGettingEventArgs e)
    {
        SelectFields += "[" + e.PropertyName + "],";
    }
    /// <summary>
    /// 设置查询咧
    /// </summary>
    /// <param name="Filds">列字段</param>
    /// <returns>当前对象</returns>
    public QuerySelect SelectField(params  Object[] Fields)
    {
        return this;     
    }


    public QuerySelect Sum(Object Field)
    {
        return this;
    }


}